﻿using System;
using System.Collections.Generic;
using System.Linq;
using Zwms.Data.BusinessObjects;
using Zwms.Data.ManagerObjects;
using Zwms.Data.CommonObject;
using ET199ComLib;

namespace Zwms.Server
{
    // 注意: 使用“重构”菜单上的“重命名”命令，可以同时更改代码、svc 和配置文件中的类名“ServiceZwms”。
    public class ServiceZwms : IServiceZwms
    {
        #region 系统
        public DateTime GetCurrentSystemTime()
        {
            return DateTime.Now;
        }

        public string GetAuthorityString()
        {
            ET199 et = new ET199();
            int nDevice = et.Enum();
            if (nDevice == 0)
            {
                return "";
            }
            et.Open(0);
            byte[] byID = (byte[])et.ID;
            return string.Format("{0:x02}{1:x02}{2:x02}{3:x02}{4:x02}{5:x02}{6:x02}{7:x02}",
                byID[7], byID[6], byID[5], byID[4], byID[3], byID[2], byID[1], byID[0]);
        }
        #endregion

        #region 系统用户
        public SysAccount GetAccountByUserCode(string sUserCode)
        {
            IManagerFactory factory = new ManagerFactory();
            ISysAccountManager manager = factory.GetSysAccountManager();

            return manager.GetById(sUserCode);
        }

        public bool UpdateAccount(SysAccount record)
        {
            IManagerFactory factory = new ManagerFactory();
            ISysAccountManager manager = factory.GetSysAccountManager();

            try
            {
                manager.Update(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }
        #endregion

        #region 菜单
        public IList<SysMenu> GetMenuByRoleCode(string sRoleCode)
        {
            IManagerFactory factory = new ManagerFactory();
            ISysMenuManager manager = factory.GetSysMenuManager();

            return manager.GetMenuByRoleCode(sRoleCode);
        }

        public bool AddMenuList(List<SysMenu> menuList)
        {
            IManagerFactory factory = new ManagerFactory();
            ISysMenuManager manager = factory.GetSysMenuManager();

            try
            {
                foreach (SysMenu record in menuList)
                {
                    manager.Save(record);
                }
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool DeleteMenuList(List<SysMenu> menuList)
        {
            IManagerFactory factory = new ManagerFactory();
            ISysMenuManager manager = factory.GetSysMenuManager();

            try
            {
                if (menuList.Count > 0)
                {
                    foreach (SysMenu record in menuList)
                    {
                        manager.Delete(record);
                    }
                    manager.Session.CommitChanges();
                }
                return true;
            }
            catch
            {
                return false;
            }
        }
        #endregion

        #region OutPlanBill
        public string InitOutPlanBillCode()
        {
            IManagerFactory factory = new ManagerFactory();
            ISysLogNoGenManager manager = factory.GetSysLogNoGenManager();

            return string.Format("OP{0:yyyyMMdd}{1}", DateTime.Now, manager.GetCurrentLogNo("OP"));
        }

        public BilOutPlanBill QueryOutPlanBill(BilOutPlanBill record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilOutPlanBillManager manager = factory.GetBilOutPlanBillManager();

            if (!string.IsNullOrWhiteSpace(record.Id))
            {
                return manager.GetById(record.Id);
            }
            else
            {
                return null;
            }
        }

        public IList<BilOutPlanBill> QueryOutPlanBillList(BilOutPlanBill record, ref PagerIndex pagerIndex)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilOutPlanBillManager manager = factory.GetBilOutPlanBillManager();
            
            return manager.GetAll(record, ref pagerIndex,false,"Id");
        }

        public bool UpdateOutPlanBill(BilOutPlanBill record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilOutPlanBillManager manager = factory.GetBilOutPlanBillManager();

            try
            {
                manager.SaveOrUpdate(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool AddOutPlanBill(BilOutPlanBill record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilOutPlanBillManager manager = factory.GetBilOutPlanBillManager();

            try
            {
                manager.Save(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool DeleteOutPlanBill(BilOutPlanBill record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilOutPlanBillManager manager = factory.GetBilOutPlanBillManager();

            try
            {
                manager.Delete(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        #endregion

        #region OutPlanBillDetail

        public BilOutPlanBillDetail QueryOutPlanBillDetail(BilOutPlanBillDetail record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilOutPlanBillDetailManager manager = factory.GetBilOutPlanBillDetailManager();

            return manager.GetById(record.OBPlanCode, record.GoodsCode);
        }

        public IList<BilOutPlanBillDetail> QueryOutPlanBillDetailList(BilOutPlanBillDetail record, ref PagerIndex pagerIndex)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilOutPlanBillDetailManager manager = factory.GetBilOutPlanBillDetailManager();

            return manager.GetAll(record, ref pagerIndex,true,"GoodsCode");
        }

        public bool UpdateOutPlanBillDetail(BilOutPlanBillDetail record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilOutPlanBillDetailManager manager = factory.GetBilOutPlanBillDetailManager();

            try
            {
                manager.Update(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool AddOutPlanBillDetail(BilOutPlanBillDetail record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilOutPlanBillDetailManager manager = factory.GetBilOutPlanBillDetailManager();

            try
            {
                manager.Save(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool AddOutPlanBillDetailList(List<BilOutPlanBillDetail> recordList)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilOutPlanBillDetailManager manager = factory.GetBilOutPlanBillDetailManager();

            try
            {
                foreach (BilOutPlanBillDetail record in recordList)
                {
                    manager.Save(record);
                }
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool DeleteOutPlanBillDetail(BilOutPlanBillDetail record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilOutPlanBillDetailManager manager = factory.GetBilOutPlanBillDetailManager();

            try
            {
                manager.Delete(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        #endregion

        #region OutBill

        public string InitOutBillCode()
        {
            IManagerFactory factory = new ManagerFactory();
            ISysLogNoGenManager manager = factory.GetSysLogNoGenManager();

            return string.Format("OB{0:yyyyMMdd}{1}", DateTime.Now, manager.GetCurrentLogNo("OB"));
        }

        public BilOutBill QueryOutBill(BilOutBill inBill)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilOutBillManager manager = factory.GetBilOutBillManager();
            if (!string.IsNullOrWhiteSpace(inBill.Id))
            {
                return manager.GetById(inBill.Id);
            }
            else
            {
                return manager.GetAll(inBill).FirstOrDefault();
            }
        }

        public IList<BilOutBill> QueryOutBillList(BilOutBill inBill, ref PagerIndex pagerIndex)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilOutBillManager manager = factory.GetBilOutBillManager();
            
            return manager.GetAll(inBill, ref pagerIndex,false,"Id");
        }

        public bool UpdateOutBill(BilOutBill record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilOutBillManager manager = factory.GetBilOutBillManager();

            try
            {
                manager.Update(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool AddOutBill(BilOutBill record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilOutBillManager manager = factory.GetBilOutBillManager();

            try
            {
                manager.Save(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool DeleteOutBill(BilOutBill record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilOutBillManager manager = factory.GetBilOutBillManager();

            try
            {
                manager.Delete(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        #endregion

        #region OutBillDetail

        public BilOutBillDetail QueryOutBillDetail(BilOutBillDetail record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilOutBillDetailManager manager = factory.GetBilOutBillDetailManager();

            return manager.GetById(record.OBCode, record.StockCode, record.GoodsCode);
        }

        public IList<BilOutBillDetail> QueryOutBillDetailList(BilOutBillDetail record, ref PagerIndex pagerIndex)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilOutBillDetailManager manager = factory.GetBilOutBillDetailManager();

            return manager.GetAll(record, ref pagerIndex,true,"GoodsCode");
        }

        public bool UpdateOutBillDetail(BilOutBillDetail record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilOutBillDetailManager manager = factory.GetBilOutBillDetailManager();

            try
            {
                manager.Update(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool AddOutBillDetail(BilOutBillDetail record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilOutBillDetailManager manager = factory.GetBilOutBillDetailManager();

            try
            {
                manager.Save(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool AddOutBillDetailList(List<BilOutBillDetail> recordList)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilOutBillDetailManager manager = factory.GetBilOutBillDetailManager();

            try
            {
                foreach (BilOutBillDetail record in recordList)
                {
                    manager.Save(record);
                }
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool DeleteOutBillDetail(BilOutBillDetail record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilOutBillDetailManager manager = factory.GetBilOutBillDetailManager();

            try
            {
                manager.Delete(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        #endregion

        #region StoGoodsStock
        public string InitGoodsStockCode()
        {
            IManagerFactory factory = new ManagerFactory();
            ISysLogNoGenManager manager = factory.GetSysLogNoGenManager();

            return string.Format("ST{0:yyyyMMdd}{1}", DateTime.Now, manager.GetCurrentLogNo("ST"));
        }

        public StoGoodsStock QueryGoodsStock(StoGoodsStock record)
        {
            IManagerFactory factory = new ManagerFactory();
            IStoGoodsStockManager manager = factory.GetStoGoodsStockManager();
            return manager.GetById(record.Id);
        }

        public IList<StoGoodsStock> QueryGoodsStockList(StoGoodsStock record, ref PagerIndex pagerIndex)
        {
            IManagerFactory factory = new ManagerFactory();
            IStoGoodsStockManager manager = factory.GetStoGoodsStockManager();
            return manager.GetAll(record, ref pagerIndex,false,"Id");
        }

        public IList<StoGoodsStock> QueryGoodsStockListOfAll(StoGoodsStock record)
        {
            IManagerFactory factory = new ManagerFactory();
            IStoGoodsStockManager manager = factory.GetStoGoodsStockManager();
            return manager.GetAll(record);
        }

        public bool UpdateGoodsStock(StoGoodsStock record)
        {
            IManagerFactory factory = new ManagerFactory();
            IStoGoodsStockManager manager = factory.GetStoGoodsStockManager();
            try
            {
                manager.SaveOrUpdate(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool AddGoodsStock(StoGoodsStock record)
        {
            IManagerFactory factory = new ManagerFactory();
            IStoGoodsStockManager manager = factory.GetStoGoodsStockManager();
            try
            {
                manager.Save(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool AddGoodsStockList(List<StoGoodsStock> recordList)
        {
            IManagerFactory factory = new ManagerFactory();
            IStoGoodsStockManager manager = factory.GetStoGoodsStockManager();
            try
            {
                foreach (StoGoodsStock record in recordList)
                {
                    manager.Save(record);
                }
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool DeleteGoodsStock(StoGoodsStock record)
        {
            IManagerFactory factory = new ManagerFactory();
            IStoGoodsStockManager manager = factory.GetStoGoodsStockManager();
            try
            {
                manager.Delete(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }
        #endregion

        #region StatStockView
        public IList<StatStockView> QueryStatStockList(StatStockView record, ref PagerIndex pagerIndex)
        {
            IManagerFactory factory = new ManagerFactory();
            IStatStockViewManager manager = factory.GetStatStockViewManager();
            //return manager.GetAll();
            return manager.GetLikeList(record, ref pagerIndex);
        }
        #endregion

        #region BilCountBill

        public string InitCountBillCode()
        {
            IManagerFactory factory = new ManagerFactory();
            ISysLogNoGenManager manager = factory.GetSysLogNoGenManager();

            return string.Format("CB{0:yyyyMMdd}{1}", DateTime.Now, manager.GetCurrentLogNo("CB"));
        }

        public BilCountBill QueryCountBill(BilCountBill record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilCountBillManager manager = factory.GetBilCountBillManager();
            return manager.GetById(record.Id);
        }

        public IList<BilCountBill> QueryCountBillList(BilCountBill record, ref  PagerIndex pagerIndex)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilCountBillManager manager = factory.GetBilCountBillManager();
            return manager.GetAll(record, ref pagerIndex,false,"Id");
        }

        public IList<BilCountBill> QueryCountBillListEx(BilCountBill record, ref  PagerIndex pagerIndex)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilCountBillManager manager = factory.GetBilCountBillManager();
            return manager.GetList(record, ref pagerIndex);
        }

        public bool UpdateCountBill(BilCountBill record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilCountBillManager manager = factory.GetBilCountBillManager();
            try
            {
                manager.Update(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool AddCountBill(BilCountBill record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilCountBillManager manager = factory.GetBilCountBillManager();
            try
            {
                manager.SaveOrUpdate(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool DeleteCountBill(BilCountBill record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilCountBillManager manager = factory.GetBilCountBillManager();
            try
            {
                manager.Delete(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }
        #endregion

        #region BilCountBillDetail
        public BilCountBillDetail QueryCountBillDetail(BilCountBillDetail record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilCountBillDetailManager manager = factory.GetBilCountBillDetailManager();
            return manager.GetById(record.CountBillCode, record.StockCode);
        }

        public IList<BilCountBillDetail> QueryCountBillDetailList(BilCountBillDetail record, ref PagerIndex pagerIndex)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilCountBillDetailManager manager = factory.GetBilCountBillDetailManager();
            return manager.GetAll(record, ref pagerIndex,true,"GoodsCode");
        }

        public bool UpdateCountBillDetail(BilCountBillDetail record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilCountBillDetailManager manager = factory.GetBilCountBillDetailManager();
            try
            {
                manager.Update(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool AddCountBillDetail(BilCountBillDetail record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilCountBillDetailManager manager = factory.GetBilCountBillDetailManager();
            try
            {
                manager.SaveOrUpdate(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool DeleteCountBillDetail(BilCountBillDetail record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilCountBillDetailManager manager = factory.GetBilCountBillDetailManager();
            try
            {
                manager.Delete(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }
        #endregion

        #region BilTransferBill
        public string InitTsfBillCode()
        {
            IManagerFactory factory = new ManagerFactory();
            ISysLogNoGenManager manager = factory.GetSysLogNoGenManager();
            return string.Format("TB{0:yyyyMMdd}{1}", DateTime.Now, manager.GetCurrentLogNo("TB"));
        }

        public BilTransferBill QueryTsfBill(BilTransferBill record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilTransferBillManager manager = factory.GetBilTransferBillManager();
            return manager.GetById(record.Id);
        }

        public IList<BilTransferBill> QueryTsfBillList(BilTransferBill record, ref PagerIndex pagerIndex)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilTransferBillManager manager = factory.GetBilTransferBillManager();
            return manager.GetAll(record, ref pagerIndex,false,"Id");
        }

        public bool UpdateTsfBill(BilTransferBill record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilTransferBillManager manager = factory.GetBilTransferBillManager();
            try
            {
                manager.Update(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool AddTsfBill(BilTransferBill record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilTransferBillManager manager = factory.GetBilTransferBillManager();
            try
            {
                manager.SaveOrUpdate(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool DeleteTsfBill(BilTransferBill record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilTransferBillManager manager = factory.GetBilTransferBillManager();
            try
            {
                manager.Delete(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }
        #endregion

        #region BilTransferBillDetail
        public BilTransferBillDetail QueryTsfBillDtl(BilTransferBillDetail record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilTransferBillDetailManager manager = factory.GetBilTransferBillDetailManager();
            return manager.GetById(record.TsfBillCode, record.StockCode, record.GoodsCode);
        }

        public IList<BilTransferBillDetail> QueryTsfBillDtlList(BilTransferBillDetail record, ref PagerIndex pagerIndex)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilTransferBillDetailManager manager = factory.GetBilTransferBillDetailManager();
            return manager.GetAll(record, ref pagerIndex,true,"GoodsCode");
        }

        public bool UpdateTsfBillDtl(BilTransferBillDetail record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilTransferBillDetailManager manager = factory.GetBilTransferBillDetailManager();
            try
            {
                manager.Update(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool AddTsfBillDtl(BilTransferBillDetail record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilTransferBillDetailManager manager = factory.GetBilTransferBillDetailManager();
            try
            {
                manager.SaveOrUpdate(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool DeleteTsfBillDtl(BilTransferBillDetail record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilTransferBillDetailManager manager = factory.GetBilTransferBillDetailManager();
            try
            {
                manager.Delete(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }
        #endregion

        #region BilTsfStockLog
        public BilTsfStockLog QueryTsfStockLog(BilTsfStockLog record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilTsfStockLogManager manager = factory.GetBilTsfStockLogManager();
            return manager.GetById(record.Id);
        }

        public IList<BilTsfStockLog> QueryTsfStockLogList(BilTsfStockLog record, ref PagerIndex pagerIndex)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilTsfStockLogManager manager = factory.GetBilTsfStockLogManager();
            return manager.GetAll(record, ref pagerIndex,false,"Id");
        }

        public bool UpdateTsfStockLog(BilTsfStockLog record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilTsfStockLogManager manager = factory.GetBilTsfStockLogManager();
            try
            {
                manager.Update(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool AddTsfStockLog(BilTsfStockLog record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilTsfStockLogManager manager = factory.GetBilTsfStockLogManager();
            try
            {
                manager.SaveOrUpdate(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool DeleteTsfStockLog(BilTsfStockLog record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilTsfStockLogManager manager = factory.GetBilTsfStockLogManager();
            try
            {
                manager.Delete(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }
        #endregion


        #region InPlanBill
        public string InitInPlanBillCode()
        {
            IManagerFactory factory = new ManagerFactory();
            ISysLogNoGenManager manager = factory.GetSysLogNoGenManager();

            return string.Format("IP{0:yyyyMMdd}{1}", DateTime.Now, manager.GetCurrentLogNo("IP"));
        }

        public BilInPlanBill QueryInPlanBill(BilInPlanBill ipBill)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilInPlanBillManager manager = factory.GetBilInPlanBillManager();

            if (!string.IsNullOrWhiteSpace(ipBill.Id))
            {
                return manager.GetById(ipBill.Id);
            }
            else
            {
                return null;
            }
        }

        public IList<BilInPlanBill> QueryInPlanBillList(BilInPlanBill ipBill, ref PagerIndex pagerIndex)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilInPlanBillManager manager = factory.GetBilInPlanBillManager();

            return manager.GetAll(ipBill, ref pagerIndex,false,"Id");
        }

        public bool UpdateInPlanBill(BilInPlanBill record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilInPlanBillManager manager = factory.GetBilInPlanBillManager();

            try
            {
                manager.SaveOrUpdate(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool AddInPlanBill(BilInPlanBill record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilInPlanBillManager manager = factory.GetBilInPlanBillManager();

            try
            {
                manager.Save(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool DeleteInPlanBill(BilInPlanBill record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilInPlanBillManager manager = factory.GetBilInPlanBillManager();

            try
            {
                manager.Delete(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        #endregion

        #region InPlanBillDetail

        public BilInPlanBillDetail QueryInPlanBillDetail(BilInPlanBillDetail ipBillDetail)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilInPlanBillDetailManager manager = factory.GetBilInPlanBillDetailManager();

            return manager.GetById(ipBillDetail.IBPlanCode, ipBillDetail.GoodsCode);
        }

        public IList<BilInPlanBillDetail> QueryInPlanBillDetailList(BilInPlanBillDetail ipBillDetail, ref PagerIndex pagerIndex)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilInPlanBillDetailManager manager = factory.GetBilInPlanBillDetailManager();

            return manager.GetAll(ipBillDetail, ref pagerIndex,true,"GoodsCode");
        }

        public bool UpdateInPlanBillDetail(BilInPlanBillDetail record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilInPlanBillDetailManager manager = factory.GetBilInPlanBillDetailManager();

            try
            {
                manager.Update(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool AddInPlanBillDetail(BilInPlanBillDetail record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilInPlanBillDetailManager manager = factory.GetBilInPlanBillDetailManager();

            try
            {
                manager.Save(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool AddInPlanBillDetailList(List<BilInPlanBillDetail> recordList)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilInPlanBillDetailManager manager = factory.GetBilInPlanBillDetailManager();

            try
            {
                foreach (BilInPlanBillDetail record in recordList)
                {
                    manager.Save(record);
                }
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool DeleteInPlanBillDetail(BilInPlanBillDetail record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilInPlanBillDetailManager manager = factory.GetBilInPlanBillDetailManager();

            try
            {
                manager.Delete(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        #endregion

        #region InBill

        public string InitInBillCode()
        {
            IManagerFactory factory = new ManagerFactory();
            ISysLogNoGenManager manager = factory.GetSysLogNoGenManager();

            return string.Format("IB{0:yyyyMMdd}{1}", DateTime.Now, manager.GetCurrentLogNo("IB"));
        }

        public BilInBill QueryInBill(BilInBill inBill)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilInBillManager manager = factory.GetBilInBillManager();
            if (!string.IsNullOrWhiteSpace(inBill.Id))
            {
                return manager.GetById(inBill.Id);
            }
            else
            {
                return manager.GetAll(inBill).FirstOrDefault();
            }
        }

        public IList<BilInBill> QueryInBillList(BilInBill inBill, ref PagerIndex pagerIndex)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilInBillManager manager = factory.GetBilInBillManager();

            return manager.GetAll(inBill, ref pagerIndex,false,"Id");
        }

        public bool UpdateInBill(BilInBill record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilInBillManager manager = factory.GetBilInBillManager();

            try
            {
                manager.Update(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool AddInBill(BilInBill record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilInBillManager manager = factory.GetBilInBillManager();

            try
            {
                manager.Save(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool DeleteInBill(BilInBill record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilInBillManager manager = factory.GetBilInBillManager();

            try
            {
                manager.Delete(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        #endregion

        #region InBillDetail

        public BilInBillDetail QueryInBillDetail(BilInBillDetail inBillDetail)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilInBillDetailManager manager = factory.GetBilInBillDetailManager();

            return manager.GetById(inBillDetail.IBCode, inBillDetail.GoodsCode);
        }

        public IList<BilInBillDetail> QueryInBillDetailList(BilInBillDetail inBillDetail, ref PagerIndex pagerIndex)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilInBillDetailManager manager = factory.GetBilInBillDetailManager();

            return manager.GetAll(inBillDetail, ref pagerIndex,true,"GoodsCode");
        }

        public bool UpdateInBillDetail(BilInBillDetail record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilInBillDetailManager manager = factory.GetBilInBillDetailManager();

            try
            {
                manager.Update(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool AddInBillDetail(BilInBillDetail record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilInBillDetailManager manager = factory.GetBilInBillDetailManager();

            try
            {
                manager.Save(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool AddInBillDetailList(List<BilInBillDetail> recordList)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilInBillDetailManager manager = factory.GetBilInBillDetailManager();

            try
            {
                foreach (BilInBillDetail record in recordList)
                {
                    manager.Save(record);
                }
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool DeleteInBillDetail(BilInBillDetail record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBilInBillDetailManager manager = factory.GetBilInBillDetailManager();

            try
            {
                manager.Delete(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        #endregion

        #region GoodsCategory
        public BaseGoodsCategory QueryGoodsCategory(BaseGoodsCategory record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBaseGoodsCategoryManager manager = factory.GetBaseGoodsCategoryManager();
            return manager.GetById(record.Id);
        }

        public IList<BaseGoodsCategory> QueryGoodsCategoryList(BaseGoodsCategory record, ref  PagerIndex pagerIndex)
        {
            IManagerFactory factory = new ManagerFactory();
            IBaseGoodsCategoryManager manager = factory.GetBaseGoodsCategoryManager();

            return manager.GetAll(record, ref pagerIndex, true, "Id");
        }

        public bool UpdateGoodsCategory(BaseGoodsCategory record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBaseGoodsCategoryManager manager = factory.GetBaseGoodsCategoryManager();

            try
            {
                manager.SaveOrUpdate(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool AddGoodsCategory(BaseGoodsCategory record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBaseGoodsCategoryManager manager = factory.GetBaseGoodsCategoryManager();

            try
            {
                manager.Save(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool DeleteGoodsCategory(BaseGoodsCategory record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBaseGoodsCategoryManager manager = factory.GetBaseGoodsCategoryManager();

            try
            {
                manager.Delete(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }
        #endregion

        #region Goods
        public BaseGood QueryGoods(BaseGood record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBaseGoodManager manager = factory.GetBaseGoodManager();
            return manager.GetById(record.Id);
        }

        public IList<BaseGood> QueryGoodsList(BaseGood record, ref  PagerIndex pagerIndex)
        {
            IManagerFactory factory = new ManagerFactory();
            IBaseGoodManager manager = factory.GetBaseGoodManager();
            
            return manager.GetAll(record, ref pagerIndex,true,"Id");
        }

        public bool UpdateGoods(BaseGood record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBaseGoodManager manager = factory.GetBaseGoodManager();

            try
            {
                manager.SaveOrUpdate(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool AddGoods(BaseGood record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBaseGoodManager manager = factory.GetBaseGoodManager();

            try
            {
                manager.Save(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool AddGoodsList(List<BaseGood> recordList)
        {
            IManagerFactory factory = new ManagerFactory();
            IBaseGoodManager manager = factory.GetBaseGoodManager();

            try
            {
                foreach (BaseGood record in recordList)
                {
                    manager.SaveOrUpdate(record);
                }
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool DeleteGoods(BaseGood record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBaseGoodManager manager = factory.GetBaseGoodManager();

            try
            {
                manager.Delete(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }
        #endregion

        #region Company
        public BaseCompany QueryCompany(BaseCompany record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBaseCompanyManager manager = factory.GetBaseCompanyManager();

            return manager.GetById(record.Id);
        }

        public IList<BaseCompany> QueryCompanyList(BaseCompany record, ref  PagerIndex pagerIndex)
        {
            IManagerFactory factory = new ManagerFactory();
            IBaseCompanyManager manager = factory.GetBaseCompanyManager();

            return manager.GetAll(record, ref pagerIndex, true, "Id");
        }

        public IList<BaseCompany> QueryCompanyListNoPage(BaseCompany record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBaseCompanyManager manager = factory.GetBaseCompanyManager();

            return manager.GetAll(record);
        }



        public bool UpdateCompany(BaseCompany record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBaseCompanyManager manager = factory.GetBaseCompanyManager();

            try
            {
                manager.SaveOrUpdate(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool AddCompany(BaseCompany record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBaseCompanyManager manager = factory.GetBaseCompanyManager();

            try
            {
                manager.Save(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool DeleteCompany(BaseCompany record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBaseCompanyManager manager = factory.GetBaseCompanyManager();

            try
            {
                manager.Delete(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }
        #endregion

        #region Unit
        public BaseUnit QueryUnit(BaseUnit record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBaseUnitManager manager = factory.GetBaseUnitManager();

            return manager.GetById(record.Id);
        }

        public IList<BaseUnit> QueryUnitList(BaseUnit record, ref  PagerIndex pagerIndex)
        {
            IManagerFactory factory = new ManagerFactory();
            IBaseUnitManager manager = factory.GetBaseUnitManager();

            return manager.GetAll(record, ref pagerIndex, true, "Id");
        }

        public bool UpdateUnit(BaseUnit record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBaseUnitManager manager = factory.GetBaseUnitManager();

            try
            {
                manager.SaveOrUpdate(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool AddUnit(BaseUnit record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBaseUnitManager manager = factory.GetBaseUnitManager();

            try
            {
                manager.Save(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool DeleteUnit(BaseUnit record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBaseUnitManager manager = factory.GetBaseUnitManager();

            try
            {
                manager.Delete(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }
        #endregion

        #region Region
        public BaseRegion QueryRegion(BaseRegion record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBaseRegionManager manager = factory.GetBaseRegionManager();

            return manager.GetById(record.Id);
        }

        public IList<BaseRegion> QueryRegionList(BaseRegion record, ref  PagerIndex pagerIndex)
        {
            IManagerFactory factory = new ManagerFactory();
            IBaseRegionManager manager = factory.GetBaseRegionManager();

            return manager.GetAll(record, ref pagerIndex,true,"Id");
        }

        public bool UpdateRegion(BaseRegion record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBaseRegionManager manager = factory.GetBaseRegionManager();

            try
            {
                manager.SaveOrUpdate(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool AddRegion(BaseRegion record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBaseRegionManager manager = factory.GetBaseRegionManager();

            try
            {
                manager.Save(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool DeleteRegion(BaseRegion record)
        {
            IManagerFactory factory = new ManagerFactory();
            IBaseRegionManager manager = factory.GetBaseRegionManager();

            try
            {
                manager.Delete(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }
        #endregion

        #region WhArea
        public WhArea QueryArea(WhArea record)
        {
            IManagerFactory factory = new ManagerFactory();
            IWhAreaManager manager = factory.GetWhAreaManager();

            return manager.GetById(record.AreaCode,record.WarehouseCode);
        }

        public IList<WhArea> QueryAreaList(WhArea record, ref  PagerIndex pagerIndex)
        {
            IManagerFactory factory = new ManagerFactory();
            IWhAreaManager manager = factory.GetWhAreaManager();

            return manager.GetAll(record, ref pagerIndex,true,"Id");
        }

        public bool UpdateArea(WhArea record)
        {
            IManagerFactory factory = new ManagerFactory();
            IWhAreaManager manager = factory.GetWhAreaManager();

            try
            {
                manager.SaveOrUpdate(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool AddArea(WhArea record)
        {
            IManagerFactory factory = new ManagerFactory();
            IWhAreaManager manager = factory.GetWhAreaManager();

            try
            {
                manager.Save(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool DeleteArea(WhArea record)
        {
            IManagerFactory factory = new ManagerFactory();
            IWhAreaManager manager = factory.GetWhAreaManager();

            try
            {
                manager.Delete(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }
        #endregion

        #region WhLocation
        public WhLocation QueryLocation(WhLocation record)
        {
            IManagerFactory factory = new ManagerFactory();
            IWhLocationManager manager = factory.GetWhLocationManager();

            return manager.GetById(record.LocationCode, record.WarehouseCode);
        }

        public IList<WhLocation> QueryLocationList(WhLocation record, ref  PagerIndex pagerIndex)
        {
            IManagerFactory factory = new ManagerFactory();
            IWhLocationManager manager = factory.GetWhLocationManager();

            return manager.GetAll(record, ref pagerIndex,true,"LocationCode");
        }

        public bool UpdateLocation(WhLocation record)
        {
            IManagerFactory factory = new ManagerFactory();
            IWhLocationManager manager = factory.GetWhLocationManager();

            try
            {
                manager.SaveOrUpdate(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool AddLocation(WhLocation record)
        {
            IManagerFactory factory = new ManagerFactory();
            IWhLocationManager manager = factory.GetWhLocationManager();

            try
            {
                manager.Save(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool DeleteLocation(WhLocation record)
        {
            IManagerFactory factory = new ManagerFactory();
            IWhLocationManager manager = factory.GetWhLocationManager();

            try
            {
                manager.Delete(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }
        #endregion

        #region WhShelf
        public WhShelf QueryShelf(WhShelf record)
        {
            IManagerFactory factory = new ManagerFactory();
            IWhShelfManager manager = factory.GetWhShelfManager();

            return manager.GetById(record.ShelfCode,record.WarehouseCode,record.AreaCode);
        }

        public IList<WhShelf> QueryShelfList(WhShelf record, ref  PagerIndex pagerIndex)
        {
            IManagerFactory factory = new ManagerFactory();
            IWhShelfManager manager = factory.GetWhShelfManager();

            return manager.GetAll(record, ref pagerIndex,true,"Id");
        }

        public bool UpdateShelf(WhShelf record)
        {
            IManagerFactory factory = new ManagerFactory();
            IWhShelfManager manager = factory.GetWhShelfManager();

            try
            {
                manager.SaveOrUpdate(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool AddShelf(WhShelf record)
        {
            IManagerFactory factory = new ManagerFactory();
            IWhShelfManager manager = factory.GetWhShelfManager();

            try
            {
                manager.Save(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool DeleteShelf(WhShelf record)
        {
            IManagerFactory factory = new ManagerFactory();
            IWhShelfManager manager = factory.GetWhShelfManager();

            try
            {
                manager.Delete(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }
        #endregion

        #region WhWarehouse
        public WhWarehouse QueryWarehouse(WhWarehouse record)
        {
            IManagerFactory factory = new ManagerFactory();
            IWhWarehouseManager manager = factory.GetWhWarehouseManager();

            return manager.GetById(record.Id);
        }

        public IList<WhWarehouse> QueryWarehouseList(WhWarehouse record, ref  PagerIndex pagerIndex)
        {
            IManagerFactory factory = new ManagerFactory();
            IWhWarehouseManager manager = factory.GetWhWarehouseManager();

            return manager.GetAll(record, ref pagerIndex,true,"Id");
        }

        public bool UpdateWarehouse(WhWarehouse record)
        {
            IManagerFactory factory = new ManagerFactory();
            IWhWarehouseManager manager = factory.GetWhWarehouseManager();

            try
            {
                manager.SaveOrUpdate(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool AddWarehouse(WhWarehouse record)
        {
            IManagerFactory factory = new ManagerFactory();
            IWhWarehouseManager manager = factory.GetWhWarehouseManager();

            try
            {
                manager.Save(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool DeleteWarehouse(WhWarehouse record)
        {
            IManagerFactory factory = new ManagerFactory();
            IWhWarehouseManager manager = factory.GetWhWarehouseManager();

            try
            {
                manager.Delete(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }
        #endregion

        #region Department
        public SysDepartment QueryDepartment(SysDepartment record)
        {
            IManagerFactory factory = new ManagerFactory();
            ISysDepartmentManager manager = factory.GetSysDepartmentManager();
            return manager.GetById(record.Id);
        }

        public IList<SysDepartment> QueryDepartmentList(SysDepartment record, ref  PagerIndex pagerIndex)
        {
            IManagerFactory factory = new ManagerFactory();
            ISysDepartmentManager manager = factory.GetSysDepartmentManager();

            return manager.GetAll(record, ref pagerIndex,true,"Id");
        }

        public bool UpdateDepartment(SysDepartment record)
        {
            IManagerFactory factory = new ManagerFactory();
            ISysDepartmentManager manager = factory.GetSysDepartmentManager();


            try
            {
                manager.SaveOrUpdate(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool AddDepartment(SysDepartment record)
        {
            IManagerFactory factory = new ManagerFactory();
            ISysDepartmentManager manager = factory.GetSysDepartmentManager();


            try
            {
                manager.Save(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool DeleteDepartment(SysDepartment record)
        {
            IManagerFactory factory = new ManagerFactory();
            ISysDepartmentManager manager = factory.GetSysDepartmentManager();


            try
            {
                manager.Delete(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }
        #endregion

        #region Dict
        public SysDict QueryDict(SysDict record)
        {
            IManagerFactory factory = new ManagerFactory();
            ISysDictManager manager = factory.GetSysDictManager();
            return manager.GetById(record.Id);
        }

        public IList<SysDict> QueryDictList(SysDict record, ref  PagerIndex pagerIndex)
        {
            IManagerFactory factory = new ManagerFactory();
            ISysDictManager manager = factory.GetSysDictManager();
            return manager.GetAll(record, ref pagerIndex,true,"DictKind");
        }

        public bool UpdateDict(SysDict record)
        {
            IManagerFactory factory = new ManagerFactory();
            ISysDictManager manager = factory.GetSysDictManager();

            try
            {
                manager.SaveOrUpdate(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool AddDict(SysDict record)
        {
            IManagerFactory factory = new ManagerFactory();
            ISysDictManager manager = factory.GetSysDictManager();

            try
            {
                manager.Save(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool DeleteDict(SysDict record)
        {
            IManagerFactory factory = new ManagerFactory();
            ISysDictManager manager = factory.GetSysDictManager();

            try
            {
                manager.Delete(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }
        #endregion

        #region LoginInf
        public SysLoginInf QueryLogInf(SysLoginInf record)
        {
            IManagerFactory factory = new ManagerFactory();
            ISysLoginInfManager manager = factory.GetSysLoginInfManager();
            return manager.GetById(record.UserCode, record.SysDate, record.LogTime, record.LogSgn);
        }

        public IList<SysLoginInf> QueryLogInfList(SysLoginInf record, ref  PagerIndex pagerIndex)
        {
            IManagerFactory factory = new ManagerFactory();
            ISysLoginInfManager manager = factory.GetSysLoginInfManager();

            return manager.GetAll(record, ref pagerIndex,false,"SysDate");
        }

        public bool UpdateLogInf(SysLoginInf record)
        {
            IManagerFactory factory = new ManagerFactory();
            ISysLoginInfManager manager = factory.GetSysLoginInfManager();
            try
            {
                manager.SaveOrUpdate(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool AddLogInf(SysLoginInf record)
        {
            IManagerFactory factory = new ManagerFactory();
            ISysLoginInfManager manager = factory.GetSysLoginInfManager();
            try
            {
                manager.Save(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool DeleteLogInf(SysLoginInf record)
        {
            IManagerFactory factory = new ManagerFactory();
            ISysLoginInfManager manager = factory.GetSysLoginInfManager();

            try
            {
                manager.Delete(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }
        #endregion

        #region OptLog
        public SysOptLog QueryOptLog(SysOptLog record)
        {
            IManagerFactory factory = new ManagerFactory();
            ISysOptLogManager manager = factory.GetSysOptLogManager();
            return manager.GetById(record.Id);
        }

        public IList<SysOptLog> QueryOptLogList(SysOptLog record, ref  PagerIndex pagerIndex)
        {
            IManagerFactory factory = new ManagerFactory();
            ISysOptLogManager manager = factory.GetSysOptLogManager();
            return manager.GetAll(record, ref pagerIndex,false,"OptDate");
        }

        public bool UpdateOptLog(SysOptLog record)
        {
            IManagerFactory factory = new ManagerFactory();
            ISysOptLogManager manager = factory.GetSysOptLogManager();
            try
            {
                manager.SaveOrUpdate(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool AddOptLog(SysOptLog record)
        {
            IManagerFactory factory = new ManagerFactory();
            ISysOptLogManager manager = factory.GetSysOptLogManager();
            try
            {
                manager.Save(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool DeleteOptLog(SysOptLog record)
        {
            IManagerFactory factory = new ManagerFactory();
            ISysOptLogManager manager = factory.GetSysOptLogManager();

            try
            {
                manager.Delete(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public String GetCurrentLogNo(string logKind)
        {
            IManagerFactory factory = new ManagerFactory();
            ISysLogNoGenManager manager = factory.GetSysLogNoGenManager();
            return string.Format("RZ{0:yyyyMMdd}{1}", DateTime.Now, manager.GetCurrentLogNo(logKind));

        }
        #endregion

        #region SysRole
        public SysRole QuerySysRole(SysRole record)
        {
            IManagerFactory factory = new ManagerFactory();
            ISysRoleManager manager = factory.GetSysRoleManager();
            return manager.GetById(record.Id);
        }
        public IList<SysRole> QuerySysRoleList(SysRole record, ref  PagerIndex pagerIndex)
        {
            IManagerFactory factory = new ManagerFactory();
            ISysRoleManager manager = factory.GetSysRoleManager();
            return manager.QuerySysRoleList(record, ref pagerIndex);
        }

        public bool UpdateSysRole(SysRole record)
        {
            IManagerFactory factory = new ManagerFactory();
            ISysRoleManager manager = factory.GetSysRoleManager();
            try
            {
                manager.SaveOrUpdate(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool AddSysRole(SysRole record)
        {
            IManagerFactory factory = new ManagerFactory();
            ISysRoleManager manager = factory.GetSysRoleManager();
            try
            {
                manager.Save(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool DeleteSysRole(SysRole record)
        {
            IManagerFactory factory = new ManagerFactory();
            ISysRoleManager manager = factory.GetSysRoleManager();

            try
            {
                manager.Delete(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }
        #endregion

        #region SysAccount
        public SysAccount QuerySysAccount(SysAccount record)
        {
            IManagerFactory factory = new ManagerFactory();
            ISysAccountManager manager = factory.GetSysAccountManager();
            return manager.GetById(record.Id);
        }

        public IList<SysAccount> QuerySysAccountList(SysAccount record, ref  PagerIndex pagerIndex)
        {
            IManagerFactory factory = new ManagerFactory();
            ISysAccountManager manager = factory.GetSysAccountManager();
            return manager.GetAll(record, ref pagerIndex,true,"Id");
        }

        public bool UpdateSysAccount(SysAccount record)
        {
            IManagerFactory factory = new ManagerFactory();
            ISysAccountManager manager = factory.GetSysAccountManager();
            try
            {
                manager.Update(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool AddSysAccount(SysAccount record)
        {
            IManagerFactory factory = new ManagerFactory();
            ISysAccountManager manager = factory.GetSysAccountManager();
            try
            {
                manager.Save(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public bool DeleteSysAccount(SysAccount record)
        {
            IManagerFactory factory = new ManagerFactory();
            ISysAccountManager manager = factory.GetSysAccountManager();

            try
            {
                manager.Delete(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }
        #endregion

        #region
        public SysConfig GetSysConfig()
        {
            IManagerFactory factory = new ManagerFactory();
            ISysConfigManager manager = factory.GetSysConfigManager();

            return manager.GetAll().FirstOrDefault();
        }

        public bool UpdateSysConfig(SysConfig record)
        {
            IManagerFactory factory = new ManagerFactory();
            ISysConfigManager manager = factory.GetSysConfigManager();

            try
            {
                manager.SaveOrUpdate(record);
                manager.Session.CommitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }
        #endregion

    }
}
